package pl.nith.battleships.windows;

import info.clearthought.layout.TableLayout;

import java.awt.Dimension;
import java.awt.Point;
import java.awt.Toolkit;

import javax.swing.JFrame;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

import pl.nith.battleships.windows.panels.BoardSurface;
import pl.nith.battleships.windows.panels.MainWindowMenuBar;

public class MainWindow extends JFrame
{
	private static final long serialVersionUID = -2560324846113754971L;
	
	private MainWindowMenuBar menuBar;
	private BoardSurface boardSurface;
	public BoardSurface getPubBoardSurface()
	{
		return boardSurface;
	}

	public MainWindow()
	{
		super();
		
		initialize();

		setVisible(true);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}
	
	private void initialize()
	{
		Toolkit t = Toolkit.getDefaultToolkit();
		Dimension d = t.getScreenSize();
		
		setSize(872, 401);
		setResizable(false);
		setLocation(new Point((d.width / 2) - (this.getWidth() / 2),
                (d.height / 2) - (this.getHeight() / 2)));
		
		setTitle("Battleships");
		// setIconImage(Icons.getSmallThalkIcon().getImage());
		
		try
		{
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		}
		catch (ClassNotFoundException e) { System.err.println(e.getMessage()); }
		catch (InstantiationException e) { System.err.println(e.getMessage()); }
		catch (IllegalAccessException e) { System.err.println(e.getMessage()); }
		catch (UnsupportedLookAndFeelException e) { System.err.println(e.getMessage()); }
		
		setJMenuBar(getMainWindowkMenuBar());
		
		double size[][] =
		{
				{ TableLayout.FILL },
				{ TableLayout.FILL }
		};
		
		setLayout(new TableLayout(size));
		
		add(getBoardSurface(), "0, 0");
	}

	private MainWindowMenuBar getMainWindowkMenuBar()
	{
		if (menuBar == null)
		{
			menuBar = new MainWindowMenuBar();
		}
		
		return menuBar;
	}
	
	private BoardSurface getBoardSurface()
	{
		if (boardSurface == null)
		{
			boardSurface = new BoardSurface();
		}
		
		return boardSurface;
	}
}
